﻿@using Apps.Web.Core;
@using Apps.Common;
@using Apps.Models.Sys;
@using Apps.Locale;
@{
    ViewBag.Title = "设置退回流程步骤";
    Layout = "~/Views/Shared/_Index_LayoutEdit.cshtml"; 
}
<input id="CustomMember" name="CustomMember" type="hidden" value="">
<div id="modalwindow" class="easyui-window" data-options="modal:true,closed:true,minimizable:false,shadow:false"></div>
 
<table class="mvctool bgb" style="width:100%;">
    <tr>
        <td>
            <div class="mvctool bgb">
                @Html.ToolButton("btnSubmit", "fa fa-sign-in", Resource.Submit, false)
                @Html.ToolButton("btnReturn", "fa fa-reply", Resource.Reply, false)  
            </div>
        </td>
        <td id="nextExamine">
            下一步审批人:
            <input id="CustomMemberList" name="CustomMemberList" readonly="readonly" type="text" style="width: 120px; display: inline; background: #dedede; ">
            <a class="fa fa-plus-square color-gray fa-lg" id="selExc" href="javascript:void(0)"></a>
            <script type="text/javascript">
                $(function () {
                    $("#selExc").click(function () {
                        $("#modalwindow").html("<iframe width='100%' height='100%' scrolling='no' frameborder='0'' src='/SysHelper/UserLookUp'></iframe>");
                        $("#modalwindow").window({ title: '选择人员', width: 700, height: 360, iconCls: 'fa fa-plus' }).window('open');
                    });
                });

                function SetSelResult(result, resultName) {
                    $("#CustomMember").val(result);
                    $("#CustomMemberList").val(resultName);
                }
                function GetSelResult() {
                    var arrayObj = new Array()
                    arrayObj[0] = $("#CustomMember").val();
                    arrayObj[1] = $("#CustomMemberList").val();
                    return arrayObj;
                }
                //ifram 返回
                function frameReturnByClose() {
                    $("#modalwindow").window('close');
                }
            </script>
        </td>
        <td><span style="line-height:26px;float:right;margin-right:30px;" id="selCount"></span></td>
    </tr>
</table> 
<div style="width:100%; margin:0 auto;">
    <div class="hr"></div>
    <div class="easyui-panel" title="审批说明" style="padding:4px;width:100%" >
        <textarea style="width:99%;height:50px;" id="CheckRemark" name="CheckRemark"></textarea> 
    </div>
    <div class="hr"></div>
    <div id="setStepLayout" title="@(ViewBag.Optype == "1" ?"下一步骤":"历史步骤")" class="easyui-panel"  style="padding:4px;width:100%" >
        <table id="StepList" style="width:100%"></table>
    </div>
    <div class="hr"></div>
</div>
    <script type="text/javascript">

        $(function () {

            if ("@ViewBag.Optype" == "1") {
                $("#CheckRemark").val("同意");
            }
            else {
                $("#CheckRemark").val("退回");
            }

            function FlowRuleFormatter(value, check) {
                var checktype = '任一';
                if (check) checktype = '会签';
                switch (value) {
                    case 1:
                        return "<span class='label label-success'>上级 ( " + checktype + " )</span>";
                        break;
                    case 2:
                        return "<span class='label label-success'>人员 ( " + checktype + " )</span>";
                        break;
                    case 3:
                        return "<span class='label label-success'>指派 ( " + checktype + " )</span>";
                        break;
                    case 4:
                        return "<span class='label label-success'>职位 ( " + checktype + " )</span>";
                        break;
                    case 5:
                        return "<span class='label label-success'>部门 ( " + checktype + " )</span>";
                        break;
                    default:
                        return "<span class='label label-success'>申请 ( " + checktype + " )</span>";
                        break;
                }
            }

            $("#btnSubmit").click(function () {

                var remark = $.trim($("#CheckRemark").val());
                if (remark == "") {
                    $.messageBox5s(Lang.Tip, "审批说明不能为空");
                    return false;
                }

                var SelectedRow = $('#StepList').datagrid("getSelected");
                if (SelectedRow != null) {
                    var userid = "";
                    if (SelectedRow.IsCustom) {
                        userid = $.trim($("#CustomMember").val());
                        if (userid == "") {
                            $.messageBox5s(Lang.Tip, "下一步审批人不能为空！");
                            return false;
                        }
                    }
                    var type=  @ViewBag.Optype;//同意为1，退回为0，终止为3
                    if (SelectedRow.Sort != 1||(SelectedRow.Sort == 1&&type==0)) {
                        if (SelectedRow.Id == '00') {
                            type=3;
                        }
                        window.parent.ICheck(remark, userid, type, SelectedRow.Id);
                    }
                    else {
                        window.parent.CreateFlow(userid);
                    }
                }
                else
                {
                    $.messageBox5s(Lang.Tip, "下一步骤不能为空");
                    return false;
                }
            });

            $('#StepList').datagrid({
                url: '@Url.Action("GetStepList")?contentId=@ViewBag.ContentId&curStepId=@ViewBag.CurStepId&optype=@ViewBag.Optype&externalurl=@ViewBag.ExternalUrl',
                //width: SetGridWidthSub(38),
                methord: 'post',
                height: SetGridHeightSub(200),
                fitColumns: true,
                sortName: 'Sort',
                sortOrder: 'Desc',
                idField: 'Id',
                pageSize: 12,
                pageList: [12, 20, 30, 40, 50],
                pagination: false,
                striped: true, //奇偶行是否区分
                singleSelect: true,//单选模式
                columns: [[
                    { field: 'checkid', title: '选择', checkbox: true },
                    { field: 'StepNo', title: '步骤', width: 30, sortable: false },
                    { field: 'Id', title: '', width: 80, hidden: true, sortable: false },
                    { field: 'Name', title: '步骤名称', width:120, sortable: false },
                    { field: 'Remark', title: '步骤说明', width: 200, sortable: false, hidden: true },
                    { field: 'FormId', title: '所属表单', width: 80, sortable: false, hidden: true },
                    { field: 'IsCustom', title: '', width: 80, sortable: false, hidden: true },
                    { field: 'FlowRule', title: '流转规则', width: 40, sortable: false, formatter: function (value, row) { return FlowRuleFormatter(value, row.IsAllCheck) } },
                    { field: 'ExecutionName', title: '审批人', width:120, sortable: false, hidden: false },
                ]],
                onLoadSuccess: function () {
                    var allRows = $('#StepList').datagrid('getRows');
                    if (allRows.length > 0) {
                        $('#StepList').datagrid('selectRow', 0);
                        $("#selCount").html("已选择了[ " + allRows[0].Name + " ]步骤    ");
                        if (allRows[0].IsCustom && "@ViewBag.Optype" == "1") {
                            $("#nextExamine").show();
                        }
                        else {
                            $("#nextExamine").hide();
                            $("#nextExamine").val();
                        }
                    }
                },
                onClickRow: function (index, data) {
                    if (data.IsCustom)
                    {
                        $("#nextExamine").show();
                    }
                    else
                    {
                        $("#nextExamine").hide();
                        $("#nextExamine").val();
                    }
                    $("#selCount").html("已选择了[ " + data.Name + " ]步骤    ");
                }
            });

            $("#btnReturn").click(function () {
                window.parent.frameReturnByClose();
            });
        });


    </script>
